package com.yh.tea.controller;


import com.yh.tea.entity.Article;
import com.yh.tea.entity.ArticleType;
import com.yh.tea.model.ArticleQuery;
import com.yh.tea.model.ArticleTypeQuery;
import com.yh.tea.service.ArticleService;
import com.yh.tea.service.ArticleTypeService;
import com.yh.tea.utiity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yh
 * @since 2024-04-07
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleTypeService articleTypeService;
    @Autowired
    private ArticleService articleService;

    //获取type
    @GetMapping("/getArticleTypeList")
    public ResponseResult getArticleTypeList(){
        return ResponseResult.success(articleTypeService.list());
    }

    @PostMapping("/add")
    public ResponseResult add(@RequestBody Article article){
        Boolean result=articleService.save(article);
        return ResponseResult.success(result?"添加成功":"添加失败",result);
    }

    @PostMapping("/del")
    public ResponseResult del(@RequestBody List<Long> ids){
        Boolean result=articleService.removeByIds(ids);
        return ResponseResult.success(result?"删除成功":"删除失败",result);
    }

    @PostMapping("/getPage")
    public ResponseResult getPage(@RequestBody ArticleQuery query){
        return articleService.getPage(query);
    }

}

